package com.dycc.main_componet.view.impl.fragment;

import android.os.Bundle;
import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.dycc.libary.base.BaseFragment;
import com.dycc.libary.view.guid.GuideView;
import com.dycc.libary.view.guid.GuideViewManager;
import com.dycc.main_componet.R;
import com.dycc.main_componet.R2;
import com.dycc.main_componet.custom.ChildViewPager;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 我的首页
 */
@Route(path = "/main_componet/fragment/Main_CIndexFragment", name = "我的首页")
public class Main_CIndexFragment extends BaseFragment {

    Unbinder unbinder;


    @BindView(R2.id.topview)
    View topview;
    @BindView(R2.id.main_c_index_tab)
    TabLayout mainCIndexTab;
    @BindView(R2.id.main_c_index_search_brlayout)
    RelativeLayout mainCIndexSearchBrlayout;

    @BindView(R2.id.main_c_index_viewpager)
    ChildViewPager mainCIndexViewpager;
    Fragment[] fragments;
    String[] titles = {"推荐", "收藏", "关注"};
    FragmentPagerAdapter adapter;
    @BindView(R.id.main_c_index_search_imageview)
    ImageView mainCIndexSearchImageview;

    public Main_CIndexFragment() {

    }

    public void showGuid() {
        new GuideViewManager(getActivity(),"")
                .setTouchOutsideDismiss(false)
                .setTipView(R.drawable.ic_launcher)
                .setHighLightStyle(GuideView.VIEWSTYLE_OVAL)
                .setMaskblurstyle(GuideView.MASKBLURSTYLE_SOLID)
                .show(mainCIndexSearchImageview);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_index;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {

        mainCIndexSearchBrlayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final BottomSheetDialog dialog = new BottomSheetDialog(getActivity());
                View dialogView = LayoutInflater.from(getActivity())
                        .inflate(R.layout.btm_dialog_layout, null);
                ListView listView = (ListView) dialogView.findViewById(R.id.listview);
                String[] array = new String[]{"item-1", "item-2", "item-3", "item-4", "item-5", "item-6", "item-7", "item-8", "item-9"};
                ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, array);
                listView.setAdapter(adapter);

                dialog.setContentView(dialogView);
                dialog.show();
            }
        });
        setWindowStatu(topview, R.color.white);//设置状态栏字体颜色
        fragments = new Fragment[]{
                (Fragment) ARouter.getInstance().build("/main_c/fragment/Main_CRCFragment").navigation(),
                (Fragment) ARouter.getInstance().build("/main_c/fragment/Main_CCollectionFragment").navigation(),
                (Fragment) ARouter.getInstance().build("/main_c/fragment/Main_CAttentionFragment").navigation()
        };

        adapter = new FragmentPagerAdapter(getChildFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments[position];
            }

            @Override
            public int getCount() {
                return (fragments != null) ? fragments.length : 0;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }
        };
        mainCIndexViewpager.setAdapter(adapter);
        mainCIndexViewpager.setOffscreenPageLimit(4);


        mainCIndexTab.setupWithViewPager(mainCIndexViewpager);
        mainCIndexTab.setTabMode(TabLayout.MODE_SCROLLABLE);
        showGuid();
    }

    @Override
    protected void initData() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
